<?php

# -- DÉBUT NOTE DE LICENCE -------------------------------------
#
# Ce fichier fait partie de Clicpage.
#
# Copyright (c) 2010 Francois (www.clicpage.net)
# Distribué selon les termes de la licence GPL version 2.0.
# Consultez le fichier LICENCE ou
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- FIN NOTE DE LICENCE ---------------------------------------

class cpContexte
{
	
	
	
	
	
	public $stack = array();
	
	
	
	
		
	public function __set($name,$var)
	{
		$this->stack[$name][] =& $var;
	}
	
	
	public function __get($name)
	{
		if (!isset($this->stack[$name])) {
			return null;
		}
		
		$n = count($this->stack[$name]);
		if ($n > 0) {
			return $this->stack[$name][($n-1)];
		}
		
		return null;
	}
	
	
	public function exists($name)
	{
		return isset($this->stack[$name][0]);
	}
	
	
	public function pop($name)
	{
		if (isset($this->stack[$name])) {
			$v = array_pop($this->stack[$name]);
			unset($v);
		}
	}
	
	
	# Méthodes statiques
	public static function global_filter($str, $encode_xml, $remove_html, $cut_string, $lower_case, $upper_case)
	{
		
		if ($remove_html) {
			$str = self::remove_html($str);
			$str = preg_replace('/\s+/',' ',$str);
		}
		
		if ($encode_xml) {
			$str = self::encode_xml($str);
		}
		
		if ($cut_string) {
			$str = self::cut_string($str,(integer) $cut_string);
		}
		
		if ($lower_case) {
			$str = self::lower_case($str);
		} elseif ($upper_case) {
			$str = self::upper_case($str);
		}
		
		return $str;
	}
	
	
	public static function cut_string($str,$l)
	{
		return text::cutString($str,$l);
	}
	
	
	public static function encode_xml($str)
	{
		return html::escapeHTML($str);
	}
	
	
	public static function remove_html($str)
	{
		return html::decodeEntities(html::clean($str));
	}
	
	
	public static function lower_case($str)
	{
		return mb_strtolower($str);
	}
	
	
	public static function upper_case($str)
	{
		return mb_strtoupper($str);
	}
	
	
}

?>